package com.object.oriented.exam.system5.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.object.oriented.exam.system5.entity.Answer;
import com.object.oriented.exam.system5.entity.Exam;
import com.object.oriented.exam.system5.entity.Score;
import com.object.oriented.exam.system5.service.AnswerService;
import com.object.oriented.exam.system5.service.ExamService;
import com.object.oriented.exam.system5.service.ScoreService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author xdf
 * @date 2023-06-14
 */
@RestController
@RequestMapping("/exam")
public class ExamController {

    @Resource
    ExamService examService;

    @Resource
    ScoreService scoreService;

    @Resource
    AnswerService answerService;

    @PostMapping("/add")
    public Boolean addExam(@RequestBody Exam exam){
        return examService.addExam(exam);
    }

    /**
     * 参加考试
     * @param score
     * @return
     */
    @PostMapping("/attend")
    public Boolean attendExam(@RequestBody Score score){
        return examService.attendExam(score);
    }

    @GetMapping("/{id}")
    public Exam getExam(@PathVariable Long id){
        return examService.getExam(id);
    }

    /**
     * 获取考试列表
     * @param current
     * @param size
     * @return
     */
    @GetMapping("/{studentId}/{current}/{size}")
    public Page<Exam> getExamInPage(@PathVariable Long studentId,@PathVariable Long current,@PathVariable Long size){
        return examService.getExamInPage(current,size,studentId);
    }

    /**
     * 完成考试,提交所有答案，并计算客观题分数
     * @param studentId
     * @param examId
     */
    @PostMapping("/finish/{studentId}/{examId}")
    public Boolean finishExam(@PathVariable Long studentId, @PathVariable Long examId, @RequestBody List<Answer> answerList){
        return scoreService.finish(studentId,examId,answerList);
    }
}
